﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Exentials.Xoox
{
    public class XElementBase
    {
        private XElement _element;
        private SortedList<int, XAttribute> _attributes;

        public XElementBase(string tag)
            : this(new XElement(SpreadsheetSchemas.MainSchema + tag))
        { }

        public XElementBase(XElement element)
        {
            _element = element;
        }

        internal XElement GetXElement()
        {
            return _element;
        }

        internal void Add(XElementBase content)
        {
            _element.Add(content.GetXElement());
        }

        internal void Add(XAttribute attribute)
        {
            _element.Add(attribute);
        }

        internal void Add(XAttribute attribute, int index)
        {
            _element.Add(attribute);
        }

        internal void Remove()
        {
            _element.Remove();
        }

        private SortedList<int, XAttribute> Attributes
        {
            get
            {
                if (this._attributes == null) this._attributes = new SortedList<int, XAttribute>();
                return this._attributes;
            }
        }
    }
}
